package com.zeronx.controller;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zeronx.utils.I18nUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;

/**
 * 国际化控制器
 * @author Goofy
 */
@Controller
@RequestMapping("/language")
public class LanguageController extends BaseController {
	
	@Autowired CookieLocaleResolver resolver;
	
	//@Autowired SessionLocaleResolver resolver;
	
	/**
	 * 语言切换
	 */
	@RequestMapping("change")
	public ModelAndView language(HttpServletRequest request,HttpServletResponse response,String language){
		
		language=language.toLowerCase();
		Locale locale = Locale.CHINA;
		if(language==null||language.equals("")){
			return new ModelAndView("redirect:/");
		}else{
			if(language.equals("en")){
				locale = Locale.ENGLISH;
			}
			resolver.setLocale(request, response, locale);
		}
		return new ModelAndView("redirect:/");
	}

}
